#!/bin/sh
# File path: ~/yeelink.sh
# author: Weihong Guan (@aGuegu) 2013-01-16
# replace <XX> with your application
 
apikey=7e94a81bf2d85e0a4e885ae3ab234927
url_core0=http://api.yeelink.net/v1.0/device/1804/sensor/2264/datapoints 
url_core1=http://api.yeelink.net/v1.0/device/1804/sensor/2265/datapoints
url_mem=http://api.yeelink.net/v1.0/device/1804/sensor/2266/datapoints
url_cpu=http://api.yeelink.net/v1.0/device/1804/sensor/2267/datapoints
 
sensors_result=$(sensors)
tmp_core0=$(echo "$sensors_result" | grep "Core 0" | egrep "[-]?[[:digit:]]+\.[[:digit:]]" -o | head -n 1)
tmp_core1=$(echo "$sensors_result" | grep "Core 1" | egrep "[-]?[[:digit:]]+\.[[:digit:]]" -o | head -n 1)
 
mem_used=$(free -m | grep "Mem" | egrep "[[:digit:]]+" -o | head -n 2 | tail -n 1)
cpu_load=$(iostat -c | tail -n 2 | egrep "[[:digit:].]+" -o | head -n 1)
 
echo $tmp_core0 
echo $tmp_core1
 
curl -d "{\"value\":$tmp_core0}" -H "U-ApiKey: $apikey" $url_core0 
curl -d "{\"value\":$tmp_core1}" -H "U-ApiKey: $apikey" $url_core1 
curl -d "{\"value\":$mem_used}" -H "U-ApiKey: $apikey" $url_mem 
curl -d "{\"value\":$cpu_load}" -H "U-ApiKey: $apikey" $url_cpu 
 
exit 0
